﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/6/2
 * 
 * 功能说明：过滤设置的添加和更新页面
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Config_WordFilter : System.Web.UI.Page
{
    protected string action = "";
    protected int wordID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        action = NetRequest.GetQueryString("Action");
        wordID = NetRequest.GetQueryInt("WordID");

        if (!IsPostBack)
        {
            switch (action)
            {
                case "Add":
                    Button1.Text = "添加";
                    break;
                case "Modify":
                    BindData();
                    Button1.Text = "修改";
                    break;
                case "Delete":
                    BindData();
                    Button1.Text = "删除";
                    this.Button1.Attributes.Add("onclick", "return confirm('确定要删除吗？');");
                    break;
            }
        }
    }

    private void BindData()
    {
        Whir.BLL.Whir_WordFilter bll = new Whir.BLL.Whir_WordFilter();
        Whir.Model.Whir_WordFilter model = bll.GetModel(wordID);
        txtWordForm.Text = model.wordFrom;
        txtWordTo.Text = model.wordTo;
        RadioButtonList1.SelectedValue = model.IsUse.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_WordFilter bll = new Whir.BLL.Whir_WordFilter();
        Whir.Model.Whir_WordFilter model;
        switch (action)
        {
            case "Add":
                model = new Whir.Model.Whir_WordFilter();
                model.wordFrom = txtWordForm.Text.Trim();
                model.wordTo = txtWordTo.Text.Trim();
                model.IsUse = Convert.ToBoolean(RadioButtonList1.SelectedValue);
                model.CreateUserID = 0;
                model.UpdateUserID = 0;
                bll.Add(model);
                break;
            case "Modify":
                model = bll.GetModel(wordID);
                model.wordFrom = txtWordForm.Text.Trim();
                model.wordTo = txtWordTo.Text.Trim();
                model.IsUse = Convert.ToBoolean(RadioButtonList1.SelectedValue);
                model.CreateUserID = 0;
                model.UpdateUserID = 0;
                bll.Update(model);
                break;
            case "Delete":
                model = bll.GetModel(wordID);
                if (model != null)
                {
                    bll.Delete(wordID);
                }
                break;
        }
        Response.Redirect("WordFilterManage.aspx");
    }
}
